<?php
/*
	+-----------------------------------------------------------------------------------------+
	| Projeto MonitoraSUS                                                                     |
	+-----------------------------------------------------------------------------------------+
	| Copyright (c) 2005-2008 Secretaria Municipal de Saúde de Belo Horizonte / Prodabel      |
	|                                                                                         |
	| Analista Responsável: Hugo Nathaniel Rodrigues <hugonr@gmail.com>, <hugo@pbh.gov.br>    |  
	|                       Consultor - GSFS - Prodabel / SMSA                                |
	| Departamento Responsável - SMSA: GPLD - Márcia Faria <marciafaria.mg@gmail.com>         |
	| Departamento Responsável - Prodabel: GSFS - Ricardo Monteiro <monteiro@pbh.gov.br>      |
	| Departamento Responsável - Prodabel: GPIS - Fabio R. Carvalho <fabao@pbh.gov.br>        |
	| Analista de Informação: Marcone <marcone.costa@pbh.gov.br>                              |
	+-----------------------------------------------------------------------------------------+
*/
session_start();
ini_set("default_charset", "ISO-8859-1");
// funcao para apresentar apenas uma parte da descricao que aparecer? na materia.
if ($_SESSION["fnom_func"] == ""){
	// header("Location: index.php");
}

include("sistema/inc.convertcharset.php");

// fim funcao resumo_descricao
include ("dados/inc.config.php");

// conexao com o banco de dados;
require_once("./dados/class.Conector.php");
$conexao = new Conector;
$unidadesaude = 310620;
$conexao->conectar($servidorbanco, $loginbanco, $senhabanco, $bancodedados);

$atual = $_GET["current"];
$menu = $_GET["menu"];
if ($menu == ""){
	$menu = "1";
}
$indicador = $_GET["ind"];
$operacao = $_GET["operacao"];

$des_plano[1] = "Eixo";
$des_plano[2] = "Objetivo Geral";
$des_plano[3] = "Diretriz";
$des_plano[4] = "Objetivo Específico";
$des_plano[5] = "Meta";
$des_plano[6] = "Opeção";
$des_plano[7] = "Ação";
$des_plano[8] = "Indicadores";
$des_plano[9] = "Estruturar";



$_SESSION["login"] = $_POST["login"];
$_SESSION["senha"] = $_POST["senha"];


if ($_POST["btlogout"] != ""){
	$_SESSION["login"] = "";
	$_SESSION["senha"] = "";
	$_SESSION["fnom_func"] = "";
	$_SESSION["fnum_func"] = 0;
	$_SESSION["fnum_nivel_acesso"] = 0;
	$_SESSION["fnum_orgao"] = 0;
	header("Location: index.php");
}



// carregando niveis de acesso
if ($_SESSION["fnum_func"] != 0){
	$sql = "select * from public.usuarios f, public.nivelacesso_niveis n ";
	$sql .= " where f.num_nivel_acesso = n.num_nivel_acesso ";
	$sql .= " and f.id_usuario = " . $_SESSION["fnum_func"];
	$sql .= " order by cod_nivel ";
	$resultado = pg_query( $sql);
	while ($rs = pg_fetch_array($resultado)){
		$nivelacesso[$rs["cod_nivel"]][1] = $rs["incluir"];
		$nivelacesso[$rs["cod_nivel"]][2] = $rs["alterar"];
		$nivelacesso[$rs["cod_nivel"]][3] = $rs["excluir"];
	}
}

if ($_GET["acao"] == "exciclo")
{
	if (($_SESSION["fnum_nivel_acesso"] == 1) || ($_SESSION["fnum_nivel_acesso"] == 2)){
		$id = explode("|", $_GET["id"]);
		$ci_num_indicador = $id[1];
		$ci_codigo_sexo = $id[2];
		$ci_codigo_faixa_etaria = $id[3];
		$ci_num_ciclodevida = $_GET["num_ciclo"];
		$sql = " delete from public.indicadores_ciclos ";
		$sql .= " where num_indicador = $ci_num_indicador ";
		$sql .= " and codigo_sexo = $ci_codigo_sexo ";
		$sql .= " and codigo_faixa_etaria = $ci_codigo_faixa_etaria ";
		$sql .= " and num_ciclodevida = $ci_num_ciclodevida ";
		pg_query( $sql);
	}
}

if ($_GET["acao"] == "adciclo")
{
	if (($_SESSION["fnum_nivel_acesso"] == 1) || ($_SESSION["fnum_nivel_acesso"] == 2)){
		$id = explode("|", $_GET["id"]);
		$ci_num_indicador = $id[1];
		$ci_codigo_sexo = $id[2];
		$ci_codigo_faixa_etaria = $id[3];
		$variavel = $_GET["id"] . "ciclodevida";
		$ci_ciclo_id = explode("|", $_POST[$variavel]);
		$ci_num_ciclodevida = $ci_ciclo_id[0];
		$ci_mesclar = $ci_ciclo_id[1];
		$sql = " delete from public.indicadores_ciclos ";
		$sql .= " where num_indicador = $ci_num_indicador ";
		$sql .= " and codigo_sexo = $ci_codigo_sexo ";
		$sql .= " and codigo_faixa_etaria = $ci_codigo_faixa_etaria ";
		$sql .= " and num_ciclodevida = $ci_num_ciclodevida ";
		pg_query( $sql);
		$sql = " insert into public.indicadores_ciclos ";
		$sql .= " (num_indicador, num_ciclodevida, mesclar, codigo_sexo, codigo_faixa_etaria) values (";
		$sql .= " $ci_num_indicador, ";
		$sql .= " $ci_num_ciclodevida, ";
		$sql .= " '$ci_mesclar', ";
		$sql .= " $ci_codigo_sexo, ";
		$sql .= " $ci_codigo_faixa_etaria) ";
		pg_query( $sql);
	}	
}






?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
        <title>MonitoraSUS</title>
        <link href="telas/styles/estilos.css" rel="stylesheet" type="text/css"/>

<? $elements = explode("-", $menu); ?>
<script language="JavaScript">
function check_date(field){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = "/";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      alert("Data Inv?lida!!!");
      DateField.select();
	  DateField.focus();
   }
}

</script>
</head>
<body>
<script language="JavaScript">
function adicionaciclodevida(codigocadastro, instrumento)
{
	document.menu2.action = "indicadores.php?acao=adciclo&id=" + codigocadastro + "&instrumento=" + instrumento;
	document.menu2.submit();
}

function excluiciclodevida(codigocadastro, instrumento, num_ciclodevida)
{
	document.menu2.action = "indicadores.php?acao=exciclo&id=" + codigocadastro + "&instrumento=" + instrumento + "&num_ciclo=" + num_ciclodevida;
	document.menu2.submit();
}

</script>
<br/>
<br/>
<br/>
Selecione o Distrito
<br/>
<div style="text-align:center; width:328px; margin-left:auto; margin-right:auto;">
<img id="Image-Maps_1201012151147086" src="telas/images/belohorizonte.gif" usemap="#Image-Maps_1201012151147086" border="0" width="328" height="450" alt="" />
<map id="_Image-Maps_1201012151147086" name="Image-Maps_1201012151147086">
<area shape="poly" coords="180,23,178,58,177,75,178,85,162,100,154,95,143,101,136,102,135,110,128,112,115,100,97,93,104,86,100,76,105,70,109,58,116,49,125,48,125,38,140,31,149,37,158,45,156,36,166,26,179,24," href="indicadores.php?unidadesaude=9000" alt="Venda Nova" title="Venda Nova"   />
<area shape="poly" coords="182,40,187,56,194,54,200,49,216,61,227,52,233,64,244,63,252,75,266,78,271,89,260,87,242,86,234,95,242,104,235,110,230,120,224,121,203,149,196,132,186,131,181,123,171,121,173,114,162,98,179,80,178,63,179,43," href="indicadores.php?unidadesaude=6000" alt="Norte" title="Norte"   />
<area shape="poly" coords="276,80,285,86,296,98,291,105,295,114,289,118,291,130,303,140,290,140,276,154,268,147,262,145,250,146,245,166,231,164,213,188,205,192,206,203,192,206,193,213,178,190,175,169,183,156,208,150,225,119,241,117,235,108,241,104,239,95,245,87,262,92,272,90,274,81," href="indicadores.php?unidadesaude=4000" alt="Nordeste" title="Nordeste"   />
<area shape="poly" coords="231,168,237,180,249,178,256,181,263,191,265,202,281,228,284,238,262,256,254,249,245,246,236,246,233,240,217,237,218,230,212,230,205,219,198,220,192,214,192,206,205,203,206,190,215,189,229,168," href="indicadores.php?unidadesaude=3000" alt="Leste" title="Leste"   />
<area shape="poly" coords="190,217,201,221,212,231,219,243,232,242,245,248,260,257,199,305,190,304,167,328,181,303,171,296,161,269,172,258,171,245,166,237,166,224,184,224,189,217," href="indicadores.php?unidadesaude=2000" alt="Centro Sul" title="Centro Sul"   />
<area shape="poly" coords="168,228,165,233,172,248,162,268,171,296,180,300,167,328,160,333,158,327,151,325,132,313,126,306,120,296,103,275,99,272,99,267,103,266,101,257,110,253,117,254,119,242,133,232,148,231,156,223,166,227," href="indicadores.php?unidadesaude=7000" alt="Oeste" title="Oeste"   />
<area shape="poly" coords="99,274,121,299,135,320,150,328,156,326,163,336,136,356,120,380,110,398,110,412,104,423,93,424,85,414,94,402,94,394,80,386,67,373,59,367,46,338,35,333,33,324,35,313,26,301,38,305,49,305,60,315,68,311,78,299,90,295,90,279,97,276," href="indicadores.php?unidadesaude=1000" alt="Barreiro" title="Barreiro"   />
<area shape="poly" coords="190,216,180,222,172,223,165,226,158,219,150,227,133,225,122,239,115,249,106,249,100,253,97,261,84,261,76,254,75,247,77,237,83,231,72,219,74,199,88,187,93,173,102,169,100,176,110,186,105,193,120,201,120,188,124,184,132,191,135,183,142,189,160,176,174,171,173,183,180,197,189,212," href="indicadores.php?unidadesaude=5000" alt="Noroeste" title="Noroeste"   />
<area shape="poly" coords="174,168,157,173,140,182,133,177,119,185,119,196,110,195,111,180,102,174,102,166,93,167,83,151,85,143,95,143,93,134,82,113,95,96,114,99,128,111,136,110,136,105,143,104,154,98,164,101,174,111,169,122,175,128,182,124,190,134,198,141,201,150,179,150,175,164," href="indicadores.php?unidadesaude=8000" alt="Pampulha" title="Pampulha"   />
<area shape="poly" coords="222,310,258,311,273,315,284,326,284,339,261,342,224,343,209,337,204,325,209,314,220,311," href="indicadores.php?unidadesaude=310620" alt="N&iacute;vel Central" title="N&iacute;vel Central"   />
<area shape="rect" coords="326,448,328,450" href="http://www.image-maps.com/index.php?aff=mapped_users_1201012151147086" alt="Image Map" title="Image Map" />
</map>
<!-- Image map text links - Start - If you do not wish to have text links under your image map, you can move or delete this DIV -->
<div style="text-align:center; font-size:12px; font-family:verdana; margin-left:auto; margin-right:auto; width:328px;">
	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=9000" title="Venda Nova">Venda Nova</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=6000" title="Norte">Norte</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=4000" title="Nordeste">Nordeste</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=3000" title="Leste">Leste</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=2000" title="Centro Sul">Centro Sul</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=7000" title="Oeste">Oeste</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=1000" title="Barreiro">Barreiro</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=5000" title="Noroeste">Noroeste</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=8000" title="Pampulha">Pampulha</a>
 | 	<a style="text-decoration:none; color:black; font-size:12px; font-family:verdana;" href="indicadores.php?unidadesaude=310620" title="N&iacute;vel Central">N&iacute;vel Central</a>
 
</div>
<!-- Image map text links - End - -->

</div>
</body>
</html>
